﻿namespace Sidvall.LogManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class LogScopeItemCategory : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.LogManager.Data.ILogScopeItemCategory
    {
        #region Public Members

        #region Category

        private string _Category;
        partial void OnBeforeCategoryPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterCategoryPropertyChanged();
        public string Category
        { 
            get
            {
                return _Category;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Category = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Category);
                    OnBeforeCategoryPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Category", eventData.Value, true, true);
                        OnAfterCategoryPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region LogScopeItemId

        private long _LogScopeItemId;
        partial void OnBeforeLogScopeItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterLogScopeItemIdPropertyChanged();
        public long LogScopeItemId
        { 
            get
            {
                return _LogScopeItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _LogScopeItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _LogScopeItemId);
                    OnBeforeLogScopeItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("LogScopeItemId", eventData.Value, true, true);
                        OnAfterLogScopeItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public LogScopeItem LogScopeItem { get; set; }
        #region LoadLogScopeItemAsync

        public async System.Threading.Tasks.Task<LogScopeItem> LoadLogScopeItemAsync()
        {
            return await LoadLogScopeItemAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScopeItem> LoadLogScopeItemAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.LogManager.Data.Fields.LogScopeItemField, global::Sidvall.LogManager.Data.Relations.LogScopeItemRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.LoadLogScopeItemAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.LogScopeItem;
        }
        public LogScopeItem LoadLogScopeItem(LogScopeItem item)
        {
            LoadInstanceField("LogScopeItem", item, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public LogScopeItemCategory Copy()
        {
            return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Copy(this);
        }
        public LogScopeItemCategory Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.LogManager.Data.ILogScopeItemCategory item)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Import(this, item);
        }
        public void Import(global::Sidvall.LogManager.Data.ILogScopeItemCategory item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<LogScopeItemCategory> SaveItemAsync()
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScopeItemCategory> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScopeItemCategory> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<LogScopeItemCategory> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.DataPortal.LogScopeItemCategoryManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Initialize(this, settings);
        }

        #endregion

        #region ILogScopeItemCategory Members

        string global::Sidvall.LogManager.Data.ILogScopeItemCategory.Category
        {
            get
            {
                return this._Category;
            }
            set
            {
                this._Category = value;
            }
        }
        long global::Sidvall.LogManager.Data.ILogScopeItemCategory.LogScopeItemId
        {
            get
            {
                return this._LogScopeItemId;
            }
            set
            {
                this._LogScopeItemId = value;
            }
        }
        global::Sidvall.LogManager.Data.ILogScopeItem global::Sidvall.LogManager.Data.ILogScopeItemCategory.LogScopeItem
        {
            get
            {
                return this.LogScopeItem;
            }
            set
            {
                this.LogScopeItem = (LogScopeItem)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public LogScopeItemCategory()
        {
        }
        public LogScopeItemCategory(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public LogScopeItemCategory(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.LogManager.SystemContext.Current.EntityFacade.LogScopeItemCategoryManager.Initialize(this);
        }

        #endregion
    }
}